

var album = {
	getlocalStorage:function(){
		var music_arr = JSON.parse(localStorage.getItem('music_arr'));
		return music_arr;
	},
	getdata: function(){
		document.querySelector('.xingzuo').innerText = localStorage.carname;
		document.querySelector('.album_img').children[0].src = localStorage.carurl;
		var str = "<ul class='list_all'>"
		var music_arr = album.getlocalStorage();
		for (var i=0;i<music_arr.length;i++) {
			str+="<li class='list' data-hash="+music_arr[i].hash+">"+
				"<span class='paly_music'></span>"+
				"<span class='music_name'>"+music_arr[i].name+"</span>"+
				"<span class='musicer'>"+music_arr[i].singer+"</span>"+
				"</li>";
		}
						
		str+="</ul>";
		document.querySelector('.music_list').innerHTML = str;
		for(var i=0;i<document.querySelectorAll('.paly_music').length;i++){
			album.clickplay(document.querySelectorAll('.paly_music')[i]);
		}
		
	},
	
	evclcik: function(){
		$('.confirm').on("touchend",function(){
			if(document.querySelector('.name').value.trim() == ''){
				alert('请输入你的姓名');
			}else{
				console.log($(this).css({"background":"url('../images/prize.png') no-repeat","background-size":"100% 100%"}));
//				this.style = "background:url('../images/prize.png') no-repeat;background-size:100% 100%;";
//				console.log(this)
				$('.enter_name').hide();
				$('.share').show();
				for (var i=0;i<$('.paly_music').length;i++) {
					$('.paly_music').eq(i).hide();
					$('.paly_music2').eq(i).hide();
				}
				document.querySelector('.name').disabled = "disabled";
			}	
		})
	},
	//点击播放
	clickplay: function(ele){
		ele.ontouchend = function(){
			var audio = document.querySelector('audio');
			audio.load();
			if(this.className == 'paly_music'){
				for(var i= 0;i<this.parentNode.parentNode.children.length;i++){
					this.parentNode.parentNode.children[i].children[0].className = "paly_music";
				}
				this.className = 'paly_music2';
				$.ajax({
					url: "http://wuyang.customer.agokara.com/kugou/getmusicurl.do",
					data: {"hash": this.parentNode.getAttribute('data-hash')},
					dataType: 'jsonp',
					async:false,
					type:"get",
					success: function(data) {
//						alert(data.url);
						audio.src = data.url;
						if(audio.paused){
							
				            audio.play();
				        }else{
				            audio.pause();
				        }
					},
				    error:function(){
				        console.log('shibai');
				    }
				});
			}else{
				this.className = 'paly_music';
				audio.pause();
			}
		}
	}
}
album.evclcik();
album.getdata();
